package cn.jinjimi.app.store;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import cn.jinjimi.app.store.dao.ZdbProductAllDao;
import cn.jinjimi.app.store.dao.ZdbProductComDao;

/**
 * Created by Roy
 * Date: 2017/1/23
 */

public class OpenHelper extends SQLiteOpenHelper {
    int version;

    public OpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        this.version = version;
    }

    public void onCreate(SQLiteDatabase db) {
        DaoMaster.createTable(db);
    }

    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        switch (oldVersion) {
            case 2:
                ZdbProductAllDao.dropTable(db, true);
            case 3:
                ZdbProductAllDao.dropTable(db, true);
                ZdbProductComDao.dropTable(db, true);
            case 7:
                String sql = "DROP TABLE IF EXISTS " + "\'" + "customers_table" + "\'";// 旧的客户数据库
                db.execSQL(sql);
        }
        onCreate(db);
    }
}